<?php
$menumark = 'vipcard';
switch ($act) {
    //#####################@ 修改分类 @#####################//
    case 'edit':
        include(pe_tpl('vipcard_edit.html'));
        break;



    case 'add':
        if(isGet()){
            $category = $db->pe_selectall('vipcategory');
            include(pe_tpl('vipcard_add.html'));
        }else if(isPost()){
            $user  = $db->pe_select('user',array('user_id'=>$_p_info['vipcard_uid']));
            $_p_info['vipcard_number'] = rand(10000000,100000000);
            //更新用户的会员卡号
            $db->pe_update('user',array('user_id'=>$user['user_id']),array('user_vipcard_number'=>$_p_info['vipcard_number']));
            $category = $db->pe_select('vipcategory',array('vipcategory_id'=>$_p_info['vipcard_category_id']));
            $_p_info['vipcard_sale'] = $category['vipcategory_sale'];
            $_p_info['vipcard_name'] = $category['vipcategory_name'];

            if($db->pe_insert('vipcard',$_p_info)){
                pe_success('添加成功');
            }else{
                pe_error('添加失败');
            }
        }


        break;

    case 'detail':

        include(pe_tpl('vipcard_detail.html'));
        break;

        //冻结会员卡
    case 'cool':
        if($db->pe_update('vipcard',array('vipcard_id'=>$_g_id),array('vipcard_state'=>0))){
            pe_success('冻结成功','admin.php?mod=vipcard');
        }else{
            pe_error('冻结失败','admin.php?mod=vipcard');
        }
        include(pe_tpl('order_detail.html'));
        break;


    case 'recover':
        if($db->pe_update('vipcard',array('vipcard_id'=>$_g_id),array('vipcard_state'=>1))){
            pe_success('恢复成功','admin.php?mod=vipcard');
        }else{
            pe_error('恢复失败','admin.php?mod=vipcard');
        }
        include(pe_tpl('order_detail.html'));
        break;



    case 'find':
        $sql = "select v.vipcard_number,v.vipcard_sale,v.vipcard_name,v.vipcard_id,v.vipcard_state,u.user_wxname,vc.vipcategory_name from wxgg_vipcard as v join wxgg_user as u on v.vipcard_uid = u.user_id join wxgg_vipcategory as vc on v.vipcard_category_id = vc.vipcategory_id where v.vipcard_number like '%{$_g_vipcard_number}%'";
//        $sql = "sele ct * from wxgg_vipcard where vipcard_number like '%{$_g_vipcard_number}%'";
        $vipcard = $db->sql_selectall($sql);
        include(pe_tpl('vipcard_list.html'));
        break;

    case 'del':
        $result = $db->pe_delete('vipcard', array('vipcard_id' => $_g_id));


        if ($result) {
            pe_success('删除成功!');
        } else {
            pe_error('删除失败...');
        }
        include(pe_tpl('vipcard_list.html'));
        break;

    //#####################@ 分类列表 @#####################//
    default :
        $sql = 'select v.vipcard_number,v.vipcard_sale,v.vipcard_name,v.vipcard_id,v.vipcard_state,u.user_wxname,vc.vipcategory_name from wxgg_vipcard as v join wxgg_user as u on v.vipcard_uid = u.user_id join wxgg_vipcategory as vc on v.vipcard_category_id = vc.vipcategory_id';
        $vipcard = $db->sql_selectall($sql);
        include(pe_tpl('vipcard_list.html'));

        break;
}
?>